package com.lkqandzzy.service.impl;

import com.lkqandzzy.dao.OpportunitiesDao;

import com.lkqandzzy.entity.Opportunities;
import com.lkqandzzy.entity.PageInfo;

import com.lkqandzzy.service.OpportunitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("opportunitiesService")
@Transactional
public class OpportunitiesServiceImpl implements OpportunitiesService {


    @Autowired
    private OpportunitiesDao opportunitiesDao;

    @Override
    public PageInfo<Opportunities> findPageInfo(String contacts, String state, Integer pageIndex, Integer pageSize) {
        PageInfo<Opportunities> pi = new PageInfo<Opportunities>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(10);
        //获取总条数
        Integer totalCount = opportunitiesDao.totalCount(contacts,state);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示销售信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Opportunities> opportunitiesList =	opportunitiesDao.getOpportunitiesDaoList(contacts,state,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(opportunitiesList);
        }
        return pi;
    }

    @Override
    public int deleteOpportunities(Integer sales_id) {
        return opportunitiesDao.deleteOpportunities(sales_id);
    }

    @Override
    public int addOpportunities(Opportunities opportunities) {
        return opportunitiesDao.addOpportunities(opportunities);
    }

    @Override
    public int updateOpportunities(Opportunities opportunities) {
        return opportunitiesDao.updateOpportunities(opportunities);
    }

    @Override
    public Opportunities findOpportunitiesById(Integer sales_id) {
        Opportunities o = opportunitiesDao.findOpportunitiesById(sales_id);
        return  o;
    }

    @Override
    public List<Opportunities> getAll() {
        List<Opportunities> OpportunitiesList = opportunitiesDao.getAll();
        return  OpportunitiesList;
    }
}
